package com.tang.model.command;

import com.tang.model.command.abst.ICommand;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/4 7:46
 * @Desc 遥控器类 ：遥控器 可以给 播放器 发送指令
 *          所以中定义了指令集合 commands
 *          播放器 player
 * @Remarks
 */
public class PlayerController {
    List<ICommand> commands = new ArrayList<>();

    private Player player;

    public PlayerController(Player player) {
        this.player = player;
    }

    public void addCommand(ICommand command) {
        command.setPlayer(this.player);
        commands.add(command);
    }

    public void execCommand(ICommand command) {
        command.setPlayer(this.player);
        command.exec();
    }

    public void execCommands() {
        if (commands.size() < 1) {
            System.out.println("暂无命令需要执行！！");
            return;
        }
        for (ICommand command : commands) {
            command.exec();
        }
        commands.clear();
    }

}
